package com.ys.service.business.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ys.entity.business.TpDataExecution;
import com.ys.entity.business.TpDataExecutionDetail;
import com.ys.mapper.business.DiySqlMapper;
import com.ys.mapper.business.TpDataExecutionDetailMapper;
import com.ys.mapper.business.TpDataExecutionMapper;
import com.ys.service.business.TpDataExecutionService;
import com.ys.util.DateUtil;

@Service("tpDataExecutionService")
public class TpDataExecutionImpl implements TpDataExecutionService {

	@Autowired
	private DiySqlMapper diySqlMapper;
	@Autowired
	private TpDataExecutionMapper tpDataExecutionMapper;
	@Autowired
	private TpDataExecutionDetailMapper tpDataExecutionDetailMapper;
	@Override
	public void add(String dayRun,
    		String purchaseDayBegin,
    		String purchaseDayEnd,
    		String latestUpdateDayBegin,
    		String latestUpdateDayEnd) {
		
		TpDataExecution entity = TpDataExecution.tpDataExecution(dayRun, purchaseDayBegin, purchaseDayEnd, latestUpdateDayBegin, latestUpdateDayEnd, 1);
		tpDataExecutionMapper.insert(entity);
	}
	@Override
	public void addDetail(String dayRun) {
		TpDataExecutionDetail entity = TpDataExecutionDetail.tpDataExecutionDetail(dayRun, 1);
		tpDataExecutionDetailMapper.insert(entity);
		
		
		String createTimeMin = DateUtil.getYYYY_MM_DD_HH_mm_ss(DateUtil.addSecond(new Date(), -300));
		Long idMax = entity.getId();
		diySqlMapper.deleteTpDataExecutionhDetailByIdMax(idMax, dayRun, createTimeMin);
	}
}
